package com.kaihong.template.ble.operation;

import java.util.UUID;

import com.kaihong.template.ble.operation.callback.adapter.BluetoothAdapterStateChangeCallback;
import com.kaihong.template.ble.operation.callback.adapter.BluetoothDeviceFoundCallback;

/**
 * Ble Central Processor
 */
public interface BleCentralProcessor<T> {
    /**
     * Turn on the phone's Bluetooth adapter
     *
     * @return error code：0 is opened，11001 is closed
     */
    int openBluetoothAdapter();

    /**
     * Turn off the mobile phone Bluetooth adapter
     *
     * @return error code：0 is success, 11001 is failed
     */
    int closeBluetoothAdapter();

    /**
     * get bluetooth state
     *
     */
    boolean getBluetoothAdapterState();

    /**
     * Monitor changes in the Bluetooth status of the mobile phone
     *
     * @param stateChangeCallback callback for state change
     */
    void onBluetoothAdapterStateChange(BluetoothAdapterStateChangeCallback stateChangeCallback);

    /**
     * Start searching for nearby Bluetooth devices
     *
     * @param services ServiceUUIDs data（UUID string array）
     * @param isAllowDuplicatesKey Indicates whether to report the same device repeatedly. If yes, the
     *        onBluetoothDeviceFound method reports the same device multiple times,
     *        However, the RSSI value varies. True indicates that the RSSI is not allowed, and
     *        false indicates that the RSSI is allowed.
     * @param interval Interval for reporting devices. The default value is 0, indicating that a new device
     *        is reported immediately. Otherwise, a new device is reported based on the input interval.
     * @return errorCode
     */
    int startBluetoothDevicesDiscovery(UUID[] services,String mac, boolean isAllowDuplicatesKey, int interval);

    /**
     * Stop searching for nearby Bluetooth devices
     *
     * @return errorCode
     */
    int stopBluetoothDevicesDiscovery();

    /**
     * Subscribe to the event of discovering a new Bluetooth device
     *
     * @param deviceFoundCallback call back find device
     */
    void onBluetoothDeviceFound(BluetoothDeviceFoundCallback deviceFoundCallback);

    /**
     * get device id
     *
     * @return UUID
     */
    String getDeviceId();

    /**
     * get BleGattDevice by deviceId
     *
     * @param deviceId bluetooth device ID
     * @return BleGattDevice
     */
    T getBleGattDevice(String deviceId);

    /**
     * Obtain the BLE connection status based on the device ID.
     *
     * @param deviceId Mac address of device
     * @return connection state
     */
    boolean getBleConnectionState(String deviceId);
}
